﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Adultorama.Ctrl
{
    class LoginController
    {
        private struct AccPass
        {
            public string user;
            public string password;
            public string type;
        };

        SqlConnection sql;
        AccPass ap = new AccPass();

        public LoginController()
        {
            connect();
        }

        void connect()
        {
            sql = new SqlConnection(Connection.Default.ConnectionString);
            sql.Open();
        }

        public bool Validate(string account, string pass)
        {
            try
            {
                bool access = false;
                //string passdb = "";
                SqlCommand com = new SqlCommand("Select * from account where account_id = '" + account + "'", sql);
                SqlDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    ap.user = reader[0].ToString();
                    ap.password = reader[1].ToString();
                    ap.type = reader[2].ToString();
                    //passdb = reader.ToString();
                }
                if (pass == ap.password/*passdb*/)
                {
                    access = true;
                }
                else
                {
                    access = false;
                }

                return access;
            }
            catch 
            {
                return false;
            }
            finally 
            { 
                sql.Close(); 
            }
        }

        public string type()
        {
            return ap.type;
        }


    }
}
